{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "api_secret = \"PS-B4K55jOU7Mb5VcxvXKV0ngy8JPaVZ\"\n",
    "api_key =  \"sTtjOitobJejRn5ac6eGrKzpSJSMKmZ1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "display_name = \"明星\"\n",
    "outer_id = \"00001\"\n",
    "user_data = \"网上搜图\"\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(CreateFace_Url, params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '4c1f64ee38dc42c9c8ae98b5306d6546',\n",
       " 'time_used': 150,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603531017,3353a343-e2e9-4d7e-80c3-c3e009796dd2',\n",
       " 'outer_id': '00001',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'outer_id':outer_id,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(GetDetail_Url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '4c1f64ee38dc42c9c8ae98b5306d6546',\n",
       " 'tags': '',\n",
       " 'time_used': 86,\n",
       " 'user_data': '网上搜图',\n",
       " 'display_name': '明星',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603531064,813edac5-c3f7-466b-a04e-f08602f08941',\n",
       " 'outer_id': '00001'}"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'4c1f64ee38dc42c9c8ae98b5306d6546',\n",
    "    'face_tokens':'b0407b9e803ebd39d511cd7956fd5bf5',\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(AddFace_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '4c1f64ee38dc42c9c8ae98b5306d6546',\n",
       " 'time_used': 76,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603531479,4c854237-eeb6-48cb-899b-1c89004eeabd',\n",
       " 'outer_id': '00001',\n",
       " 'failure_detail': [{'reason': 'INVALID_FACE_TOKEN',\n",
       "   'face_token': 'b0407b9e803ebd39d511cd7956fd5bf5'}]}"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "Update_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/update\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'4c1f64ee38dc42c9c8ae98b5306d6546',\n",
    "    'user_data':\"网上搜图\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(Update_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '4c1f64ee38dc42c9c8ae98b5306d6546',\n",
       " 'request_id': '1603531569,37f0a898-2234-4c82-b0c0-bf9c76389bff',\n",
       " 'time_used': 69,\n",
       " 'outer_id': '00001'}"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "image1 = \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603535031555&di=49f6b2e9be2afd5b126c83c4350a31e8&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20180630%2F52ca7be7a6cd45e39803f710b9d2a739.jpeg\"\n",
    "image2 = \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603539519310&di=6ca5d08235d6954f04fa83f9c05459f4&imgtype=0&src=http%3A%2F%2Fp3.img.cctvpic.com%2F20120222%2Fimages%2F1329906217197_1329906217197_r.jpg\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "\n",
    "payload ={\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url1':image1,\n",
    "    'image_url2':image2\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(Compare_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faces1': [{'face_rectangle': {'width': 137,\n",
       "    'top': 159,\n",
       "    'left': 275,\n",
       "    'height': 137},\n",
       "   'face_token': '94586b44c8510d8087d862d18cc6664e'}],\n",
       " 'faces2': [{'face_rectangle': {'width': 146,\n",
       "    'top': 146,\n",
       "    'left': 173,\n",
       "    'height': 146},\n",
       "   'face_token': '867ed75d16a415da80da37bd05e98a27'}],\n",
       " 'time_used': 800,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'confidence': 35.623,\n",
       " 'image_id2': 'WTWapMG9pSBSsXnZj4GlUw==',\n",
       " 'image_id1': 'Ha+UxhBsuph2QjCYIgOcxw==',\n",
       " 'request_id': '1603531833,aa800af6-6b96-4072-ab5a-d257c69bb9d0'}"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
